
package horde.minefield.andres;

import horde.control.AutomatonBehavior;
import horde.interfaces.Requests;
import horde.patterns.Agent;
import horde.patterns.Msg;
import horde.patterns.master.MasterAgent;
import horde.internalResources.Launcher;
import horde.utils.RawLoader;
import java.awt.Color;

/**
 * @author Andres
 */
public class smartSmithTest {

    public static void test () {
        Launcher L = new Launcher("Smith Launcher",RawLoader.hordeSplash, Color.red, 220);
        L.showMessage("Creating master agent...");
        MasterAgent the_architect = new MasterAgent("Architect");
        Requests requestLink = Requests.createRequests(the_architect);
        try {Thread.sleep(2000);} catch (Exception e) {}
        L.showMessage("Creating agent smith...");
        agentSmithCoreTest smithCore = new agentSmithCoreTest();
//        DummyBehavior dummy = new DummyBehavior(smithCore);
        AutomatonBehavior automaton = new AutomatonBehavior("/horde/minefield/andres/automatonTest.xml");
//        Agent smith = new Agent ("Smith", dummy, smithCore, requestLink);
        try {Thread.sleep(2000);} catch (Exception e) {}
        L.showMessage("Assigning agent Smith to a Master...");
        Agent smith = new Agent ("Smith", automaton, smithCore, requestLink);
        the_architect.addAgent(smith);
        /* Test message */
//        Msg sayHi = new Msg ("Tester", "Smith", Msg.TYPE_REQUEST, "sayHi");
        Msg start = new Msg ("Tester", "Smith", Msg.TYPE_REQUEST, "start", new Integer(5));
//        the_architect.sendMessage(sayHi);
        the_architect.sendMessage(start);
        try {Thread.sleep(2000);} catch (Exception e) {}
        System.err.println ("Starting agents...");
        /* Start the gunfire */
        L.showMessage("Ready to run...");
        /* Wait for the fading to start */
        if (L.fadeAndDispose()) the_architect.startAgents();
        System.err.println ("Running " + the_architect.getNumberOfAgentsRunning() + " agents");
        try {
            System.out.println ("Stopping for a couple seconds...");
            Thread.sleep(2000);
        } catch (Exception e) {
            System.err.println ("Failure stopping main thread");
        }
        /* Send the same message to check status */
        the_architect.sendMessage(start);
        try {
            System.out.println ("Stopping for a couple seconds...");
            Thread.sleep(2000);
        } catch (Exception e) {
            System.err.println ("Failure stopping main thread");
        }
        /* Send the correct message */
        Msg anotherMsg = new Msg ("Tester", "Smith", Msg.TYPE_REQUEST, "work");
        the_architect.sendMessage(anotherMsg);

//        /* Politely request smith to stop messing around */
        try {Thread.sleep(5000);the_architect.stopAgents();} catch (Exception e) {}
//        the_architect.stopAgents();
    }

    public static void test2 () {
        MasterAgent the_architect = new MasterAgent("Architect");
        String corePath = "horde.minefield.andres.agentSmithCoreTest";
        String fsmPath = "/horde/minefield/andres/automatonTest.xml";

        Agent smith = new Agent ("Smith", fsmPath, corePath);
        the_architect.addAgent(smith);
        /* Test message */
//        Msg sayHi = new Msg ("Tester", "Smith", Msg.TYPE_REQUEST, "sayHi");
        Msg start = new Msg ("Tester", "Smith", Msg.TYPE_REQUEST, "start", new Integer(5));
//        the_architect.sendMessage(sayHi);
        the_architect.sendMessage(start);
        try {Thread.sleep(2000);} catch (Exception e) {}
        System.err.println ("Starting agents...");
        /* Start the gunfire */
        the_architect.startAgents();
        System.err.println ("Running " + the_architect.getNumberOfAgentsRunning() + " agents");
        try {
            System.out.println ("Stopping for a couple seconds...");
            Thread.sleep(2000);
        } catch (Exception e) {
            System.err.println ("Failure stopping main thread");
        }
        /* Send the same message to check status */
        the_architect.sendMessage(start);
        try {
            System.out.println ("Stopping for a couple seconds...");
            Thread.sleep(1000);
        } catch (Exception e) {
            System.err.println ("Failure stopping main thread");
        }
        /* Send the correct message */
        Msg anotherMsg = new Msg ("Tester", "Smith", Msg.TYPE_REQUEST, "work");
        the_architect.sendMessage(anotherMsg);

//        /* Politely request smith to stop messing around */
        try {Thread.sleep(3000);the_architect.stopAgents();} catch (Exception e) {}
//        the_architect.stopAgents();
    }
}
